*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 
gl CONTROL = "educ year_birth sex#age urban_hk prov_hk##c.(year_birth ) "


******* Bargaining ***********
use "$path2/min_marr_policy", clear 
ren pid pid_t 
ren spouse_pid pid 
ren educ educ_t
set more off 
fmerge 1:1 pid using "$path2/min_marr_policy", keepusing(educ) keep(3)
ren educ educ_sp
ren educ_t educ 
drop if mi(hktype)

replace urban = hktype == 1 
gen urban_hk = hktype == 2 

cap gen female = 1-male
cap gen han = 1- minority 

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 


egen fine_16_25 = rowmean(fine_16-fine_25)

gen educ_sp_h = educ_sp >= 4 

replace educ_sp_h = educ_sp_h *100


cap erase "$path3/marriage_match_prov.xls"
cap erase "$path3/marriage_match_prov.txt"
*** Table 3 ***

preserve
keep if marry_2 == 1

foreach eth in "han ==0" "han ==1"  {
foreach policy in "1""mino_policy  ==1" "mino_policy ==0" {

reghdfe educ_sp_h fine_16_25 [aw = aw]  if  `eth' & `policy', a($CONTROL)   cluster(prov_hk)
su educ_sp_h [aw = aw] if `eth' & `policy'
outreg2 using "$path3/marriage_match_prov.xls", append  ctit(educ_sp_h & `policy' & `eth')  dec(3) bracket addstat(Y, `r(mean)') 
}
}
restore

reghdfe educ_sp_h fine_16_25 [aw = aw]  if  marry_1 == 1 & han == 1, a($CONTROL)   cluster(prov_hk)
su educ_sp_h [aw = aw]  if  marry_1 == 1 & han == 1
outreg2 using "$path3/marriage_match_prov.xls", append   dec(3) bracket addstat(Y, `r(mean)') 

reghdfe educ_sp_h fine_16_25 [aw = aw]  if  marry_1 == 1 & han == 1 & mino_policy == 1, a($CONTROL)   cluster(prov_hk)
su educ_sp_h [aw = aw] if  marry_1 == 1 & han == 1 & mino_policy == 1
outreg2 using "$path3/marriage_match_prov.xls", append   dec(3) bracket addstat(Y, `r(mean)') 

reghdfe educ_sp_h fine_16_25 [aw = aw]  if  marry_1 == 1 & han == 1 & mino_policy == 0, a($CONTROL)   cluster(prov_hk)
su educ_sp_h [aw = aw] if  marry_1 == 1 & han == 1 & mino_policy == 0
outreg2 using "$path3/marriage_match_prov.xls", append   dec(3) bracket addstat(Y, `r(mean)') 

